package com.sky.zzh.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.next.app.StandardApplication;
import com.next.util.Log;

/**
 * 
 * 
 * @author skypan
 * 
 */
public class UserInfoManager {
	/**
	 * 
	 */
	private String userId;
	private int uid;

	private boolean personInfoState;
	private boolean firstInstall;//
	private boolean autoLogin;//
	private String photoUrl;
	
	private String photoQQ;//QQ头像
	private String photoSina;//sina头像
	private String photoWeixin;//微信头像
	
	private String nickQQ;//QQ昵称
	private String nickSina;//sina昵称
	private String nickWeixin;//微信昵称
	private String loginType;//登陆类型
	
	public String getLoginType() {
		return loginType;
	}

	public void setLoginType(String loginType) {
		this.loginType = loginType;
	}

	public String getNickQQ() {
		return nickQQ;
	}

	public void setNickQQ(String nickQQ) {
		this.nickQQ = nickQQ;
	}

	public String getNickSina() {
		return nickSina;
	}

	public void setNickSina(String nickSina) {
		this.nickSina = nickSina;
	}

	public String getNickWeixin() {
		return nickWeixin;
	}

	public void setNickWeixin(String nickWeixin) {
		this.nickWeixin = nickWeixin;
	}

	public String getPhotoQQ() {
		return photoQQ;
	}

	public void setPhotoQQ(String photoQQ) {
		this.photoQQ = photoQQ;
	}

	public String getPhotoSina() {
		return photoSina;
	}

	public void setPhotoSina(String photoSina) {
		this.photoSina = photoSina;
	}

	public String getPhotoWeixin() {
		return photoWeixin;
	}

	public void setPhotoWeixin(String photoWeixin) {
		this.photoWeixin = photoWeixin;
	}

	public String getPhotoUrl() {
		return photoUrl;
	}

	public void setPhotoUrl(String photoUrl) {
		this.photoUrl = photoUrl;
	}

	private boolean isAuth;
	private String appPwd;
	private boolean isLock;
	private String UUID;
	private String username;
	private boolean isCustomer;// 是否启用自定义
	private boolean isNaozhong;//是否打开闹钟
	private boolean isJiushui;//是否久睡设置
	private boolean isLichuang;//是否离床设置
	private String naozhongTime;//闹钟时间
	private String jiushui;//久睡
	private int lichuangTime;//离床提醒秒数
	public int getLichuangTime() {
		return lichuangTime;
	}

	public void setLichuangTime(int lichuangTime) {
		this.lichuangTime = lichuangTime;
	}

	public String getJiushui() {
		return jiushui;
	}

	public void setJiushui(String jiushui) {
		this.jiushui = jiushui;
	}

	public String getLichuang() {
		return lichuang;
	}

	public void setLichuang(String lichuang) {
		this.lichuang = lichuang;
	}

	private String lichuang;//离床
	
	
	public String getNaozhongTime() {
		return naozhongTime;
	}

	public void setNaozhongTime(String naozhongTime) {
		this.naozhongTime = naozhongTime;
	}

	public boolean isNaozhong() {
		return isNaozhong;
	}

	public void setNaozhong(boolean isNaozhong) {
		this.isNaozhong = isNaozhong;
	}

	public boolean isJiushui() {
		return isJiushui;
	}

	public void setJiushui(boolean isJiushui) {
		this.isJiushui = isJiushui;
	}

	public boolean isLichuang() {
		return isLichuang;
	}

	public void setLichuang(boolean isLichuang) {
		this.isLichuang = isLichuang;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public boolean isCustomer() {
		return isCustomer;
	}

	public void setCustomer(boolean isCustomer) {
		this.isCustomer = isCustomer;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	private String startTime = "20:00";// 开始时间
	private String endTime = "06:00";// 结束时间
	
	public String getUUID() {
		return UUID;
	}

	public void setUUID(String uUID) {
		UUID = uUID;
	}

	public boolean isLock() {
		return isLock;
	}

	public void setLock(boolean isLock) {
		this.isLock = isLock;
	}

	public String getAppPwd() {
		return appPwd;
	}

	public void setAppPwd(String appPwd) {
		this.appPwd = appPwd;
	}

	public boolean isAuth() {
		return isAuth;
	}

	public void setAuth(boolean isAuth) {
		this.isAuth = isAuth;
	}

	private String email;
	private String moblie;
	private String displayName;
	private String session;

	public String getSession() {
		return session;
	}

	public void setSession(String session) {
		this.session = session;
	}

	/**
	 * 
	 */
	private String name;
	/**
	 * 
	 */
	private String password;

	private static UserInfoManager _instance;

	public static synchronized UserInfoManager getInstance() {
		if (_instance == null) {
			_instance = new UserInfoManager();
			_instance.sync(StandardApplication.getInstance(), false);
		}
		return _instance;
	}

	/**
	 * 
	 * 
	 * @param context
	 * @param isWrite
	 */
	public void sync(Context context, boolean isWrite) {
		SharedPreferences pref = context.getSharedPreferences(ConfigDefinition.PREFS_DATA, Context.MODE_PRIVATE);
		if (isWrite) {
			SharedPreferences.Editor editor = pref.edit();
			if (userId != null) {
				editor.putString("userId", userId);
			}
			if (name != null) {
				editor.putString("name", name);
			}
			if (password != null) {
				editor.putString("password", password);
			}
			if (moblie != null) {
				editor.putString("moblie", moblie);
			}
			if (email != null) {
				editor.putString("email", email);
			}
			if (displayName != null) {
				editor.putString("displayName", displayName);
			}
			if (session != null) {
				editor.putString("session", session);
			}
			if (appPwd != null) {
				editor.putString("appPwd", appPwd);
			}
			if (UUID != null) {
				editor.putString("UUID", UUID);
			}
			if (username != null) {
				editor.putString("username", username);
			}
			if (startTime != null) {
				editor.putString("startTime", startTime);
			}
			if (endTime != null) {
				editor.putString("endTime", endTime);
			}
			if(naozhongTime != null){
				editor.putString("naozhongTime", naozhongTime);
			}
			if(jiushui != null){
				editor.putString("jiushui", jiushui);
			}
			if(lichuang != null){
				editor.putString("lichuang", lichuang);
			}
			if(photoUrl != null){
				editor.putString("photoUrl", photoUrl);
			}
			if(photoQQ != null){
				editor.putString("photoQQ", photoQQ);
			}
			if(photoSina != null){
				editor.putString("photoSina", photoSina);
			}
			if(photoWeixin != null){
				editor.putString("photoWeixin", photoWeixin);
			}
			if(nickQQ != null){
				editor.putString("nickQQ", nickQQ);
			}
			if(nickSina != null){
				editor.putString("nickSina", nickSina);
			}
			if(nickWeixin != null){
				editor.putString("nickWeixin", nickWeixin);
			}
			if(loginType != null){
				editor.putString("loginType", loginType);
			}
			editor.putInt("lichuangTime", lichuangTime);
			editor.putBoolean("personInfoState", personInfoState);
			editor.putBoolean("firstInstall", firstInstall);
			editor.putBoolean("autoLogin", autoLogin);
			editor.putBoolean("isAuth", isAuth);
			editor.putBoolean("isLock", isLock);
			editor.putBoolean("isCustomer", isCustomer);
			editor.putBoolean("isNaozhong", isNaozhong);
			editor.putBoolean("isLichuang", isLichuang);
			editor.putBoolean("isJiushui", isJiushui);
			editor.commit();

		} else {
			this.userId = pref.getString("userId", null);
			this.name = pref.getString("name", null);
			this.password = pref.getString("password", null);
			this.moblie = pref.getString("moblie", null);
			this.email = pref.getString("email", null);
			this.displayName = pref.getString("displayName", null);
			this.personInfoState = pref.getBoolean("personInfoState", false);
			this.firstInstall = pref.getBoolean("firstInstall", true);//
			this.autoLogin = pref.getBoolean("autoLogin", true);//
			this.session = pref.getString("session", null);
			this.isAuth = pref.getBoolean("isAuth", true);//
			this.appPwd = pref.getString("appPwd", appPwd);
			this.isLock = pref.getBoolean("isLock", false);
			this.UUID = pref.getString("UUID", null);
			this.username = pref.getString("username", null);
			this.startTime = pref.getString("startTime", "20:00");
			this.endTime = pref.getString("endTime", "06:00");
			this.isCustomer = pref.getBoolean("isCustomer", false);
			this.isJiushui = pref.getBoolean("isJiushui", false);
			this.isLichuang = pref.getBoolean("isLichuang", false);
			this.isNaozhong = pref.getBoolean("isNaozhong", false);
			this.naozhongTime = pref.getString("naozhongTime", "07:30");
			this.jiushui = pref.getString("jiushui", "00:15");
			this.lichuang = pref.getString("lichuang", "超时15秒");
			this.photoUrl = pref.getString("photoUrl", null);
			this.photoQQ = pref.getString("photoQQ", photoQQ);
			this.photoSina = pref.getString("photoSina", photoSina);
			this.photoWeixin = pref.getString("photoWeixin", photoWeixin);
			this.nickQQ = pref.getString("nickQQ", nickQQ);
			this.nickSina = pref.getString("nickSina", nickSina);
			this.nickWeixin = pref.getString("nickWeixin", nickWeixin);
			this.lichuangTime = pref.getInt("lichuangTime", 0);
			this.loginType = pref.getString("loginType", null);
		}
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isPersonInfoState() {
		return personInfoState;
	}

	public void setPersonInfoState(boolean personInfoState) {
		this.personInfoState = personInfoState;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMoblie() {
		return moblie;
	}

	public void setMoblie(String moblie) {
		this.moblie = moblie;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public boolean isFirstInstall() {
		return firstInstall;
	}

	public void setFirstInstall(boolean firstInstall) {
		this.firstInstall = firstInstall;
	}

	public boolean isAutoLogin() {
		return autoLogin;
	}

	public void setAutoLogin(boolean autoLogin) {
		this.autoLogin = autoLogin;
	}

	public int getUid() {
		return uid;
	}

	public void setUid(int uid) {
		this.uid = uid;
	}

	public void print() {
		Log.i("userInfo", "userId=" + userId + " pwd=" + password + " name=" + name + " moblie=" + moblie + "emial=" + email);
	}

}
